import React, { Fragment, Component } from 'react'
import { BrowserRouter as Router, Switch, Route } from 'react-router-dom'
import NavHeader from 'containers/navHeader'
import navList from 'src/navList.js'
const routeMap = (routes, matchUrl) =>  
    routes.map(({name, path, exact = true, component, children}) => (
        <Route path = { `${ matchUrl ? matchUrl : ''}${path}` } exact = { exact } component = { component ? component : ({match}) => (<Fragment>{routeMap(children, match.url)}</Fragment>) } key = { name }/>
    ))
export default (routes) => class RouterMap extends Component {
    render() {
        return (
            <Router>
                <Fragment>
                    <NavHeader navList={navList}/>
                    <Switch>
                        {
                            routeMap(routes)
                        }
                    </Switch>
                </Fragment>
            </Router>
        )
    }
} 